angular.module('Controller')
.controller('WFRoleManageEditCtrl', ($scope,NgTableParams,commonUtil,wfAlert,commonConstant,$http, $uibModalInstance, items) ->
    type=items.type
    $scope.data=items.data
    $scope.modalTitle=if type=='new' then '新建角色' else '编辑角色'
    $scope.modalTypeList=commonConstant.authorizationTypeList()
    $scope.modalEnableList=commonConstant.enabledList()
    $scope.newData=()->
        postData={
            name:$scope.data.name
            description:$scope.data.description
            type:$scope.data.type
            enabled:$scope.data.enabled
        }
        $http.post('@ostengar/role',postData)
        .success((resp)->
            if resp.code==0
                wfAlert.toastInfo('角色创建成功')
            else
                wfAlert.toastError('角色创建失败：',resp.message)
            $uibModalInstance.close('done')
        )
    $scope.editData=()->
        postData={
            name:$scope.data.name
            description:$scope.data.description
            type:$scope.data.type
            enabled:$scope.data.enabled
        }
        $http.put('@ostengar/role/'+$scope.data.id,postData)
        .success((resp)->
            if resp.code==0
                wfAlert.toastInfo('角色编辑成功')
                $uibModalInstance.close('done')
            else
                wfAlert.toastError('角色编辑失败：',resp.message)
        )
    $scope.confirm = ()->
        if type=='new'
            $scope.newData()
        else
            $scope.editData()
    $scope.cancel =()->
        $uibModalInstance.dismiss('cancel')

)